package com.liang.service.impl;



import com.liang.mapper.RolesDAO;
import com.liang.pojo.Roles;
import com.liang.service.RolesService;
import com.liang.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *@作者:lsk
 *Service实现类
 *@Date:2023/07/13
*/
@Service
public class RolesServiceImpl implements RolesService {


	@Resource
	private RolesDAO rolesdao;


	/**
	根据RoleId查询
	*/
	public Object selectByRoleId(Integer roleId){
		return rolesdao.selectByRoleId(roleId);
	}


	/**
	根据RoleId更新
	*/
	public Integer updateByRoleId(Roles demo){
		if(demo.getRoleId() == null){
			return 0;
		}
		demo.setRole_updatetime(DateUtils.getTodayDateTime());
		return rolesdao.updateByRoleId( demo);


	}



	/**
	根据RoleId删除
	*/
	public Integer deleteByRoleId(Integer roleId){
		if(roleId == null){
			return 0;
		}
		return rolesdao.deleteByRoleId(roleId);
	}





	/**
	 insert:(插入)
	*/
	public Object insert(Roles demo){
		demo.setRoleTime(DateUtils.getTodayDateTime());
		rolesdao.insert(demo);
		return demo;
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	public Integer insertOrUpdate(Roles demo){
		return rolesdao.insertOrUpdate(demo);
	}



	/**
	 insertBath:(批量插入)
	*/
	public Integer insertBatch(List<Roles> list){
		return rolesdao.insertBatch(list);
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
	public Integer insertOrUpdateBatch(List<Roles> list){
		return rolesdao.insertOrUpdateBatch(list);
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	public List<Roles> selectList(Map<String,Object> param){
		if(param.get("pageNum") != null){
			int start = Integer.parseInt(param.get("pageSize").toString()) * (Integer.parseInt(param.get("pageNum").toString()) - 1);
			param.put("pageNum",start);
		}
		return rolesdao.selectList(param);
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
	public Long selectCount(Map<String,Object> param){
		return rolesdao.selectCount(param);
	}



}